﻿package mortal.game.view.rebate
{
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.dayRecharge.*;
    import mortal.game.view.rebate.dayTarget.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.rebate.openServerSevenDay.panel.*;
    import mortal.game.view.rebate.shop.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class RebateModule extends BaseWindow
    {
        protected var _tabBg:ScaleBitmap;
        protected var _rightBg:ScaleBitmap;
        public var tabPanel:RebateTabsPanel;
        private var _clsVec:Vector.<Class>;
        public var curPanel:GSprite;
        private var _tabData:Array;
        private var _selectIndex:int = -1;

        public function RebateModule(param1:ILayer = null)
        {
            this._clsVec = new Vector.<Class>;
            this._tabData = [];
            super(param1);
            setSize(879, 613 - 30);
            title = "" + Language.getString(71926);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.rebate, this.onResLoadRebate);
            return;
        }// end function

        private function onResLoadRebate() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this._tabBg = UIFactory.bg(8, 36, 169, 540, this, ImagesConst.PanelBg);
            this._rightBg = UIFactory.bg(180, 37, 692, 539, this, ImagesConst.PanelBg);
            this.tabPanel = UIFactory.getUICompoment(RebateTabsPanel, 13, 41, this);
            this.tabPanel.setAttr(100, 60, 164, 64, -3);
            this.tabPanel.cellB = RebateTabSCellSp;
            this.tabPanel.configEventListener(EventName.RebateTabSelect, this.onTabChangeHd);
            this.initPanel();
            this.setLeftTabData();
            this.selectFirstTatOnload();
            return;
        }// end function

        public function selectFirstTatOnload() : void
        {
            if (this.tabPanel)
            {
                this._selectIndex = -1;
                this.tabPanel.setSelectEff(0);
                Dispatcher.dispatchEvent(new DataEvent(EventName.RebateShowRewardTabEffect));
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tabBg = null;
            this._rightBg = null;
            this.tabPanel = null;
            if (this.curPanel)
            {
                this.curPanel.dispose();
                this.curPanel = null;
            }
            this._clsVec.length = 0;
            this._tabData.length = 0;
            this._selectIndex = -1;
            return;
        }// end function

        private function setLeftTabData() : void
        {
            this.tabPanel.setData(this._tabData);
            return;
        }// end function

        public function initPanel() : void
        {
            this._tabData = [];
            this.addOpenSeverPanel();
            this.addDayTargetPanel();
            this.addShopPanel();
            this.addDayRechargePanel();
            return;
        }// end function

        private function addOpenSeverPanel() : void
        {
            if (RebateUtil.isOpenSevenDayOpen())
            {
                this._clsVec.push(OpenServerDayPanel);
                this._tabData.push(RebateTitleConst.SevenDay);
            }
            return;
        }// end function

        private function addShopPanel() : void
        {
            if (RebateUtil.isShopOpen())
            {
                this._clsVec.push(RebateShopPanel);
                this._tabData.push(RebateTitleConst.Shop);
            }
            return;
        }// end function

        private function addDayTargetPanel() : void
        {
            if (RebateUtil.isDayTargetOpen())
            {
                this._clsVec.push(RebateDayTargetPanel);
                this._tabData.push(RebateTitleConst.DayTarget);
            }
            return;
        }// end function

        private function addDayRechargePanel() : void
        {
            if (RebateUtil.isDayRechargeOpen())
            {
                this._clsVec.push(RebateDayRechargePanel);
                this._tabData.push(RebateTitleConst.DayRecharge);
            }
            return;
        }// end function

        public function openHasRewardByName(param1:int) : void
        {
            if (this._tabData == null)
            {
                return;
            }
            var _loc_2:* = this._tabData.indexOf(param1);
            if (_loc_2 == -1)
            {
                return;
            }
            var _loc_3:* = new DataEvent("", _loc_2);
            this.tabPanel.setSelectEff(_loc_2);
            this.onTabChangeHd(_loc_3);
            return;
        }// end function

        private function onTabChangeHd(event:DataEvent) : void
        {
            var _loc_3:GSprite = null;
            var _loc_2:int = 0;
            if (event != null)
            {
                _loc_2 = int(event.data);
            }
            if (_loc_2 < 0 || this._clsVec == null || _loc_2 >= this._clsVec.length)
            {
                return;
            }
            if (this._selectIndex == _loc_2)
            {
                return;
            }
            this._selectIndex = _loc_2;
            _loc_3 = UIFactory.getUICompoment(this._clsVec[_loc_2]);
            if (_loc_3 != this.curPanel)
            {
                if (this.curPanel && !this.curPanel.isDisposed)
                {
                    this.curPanel.dispose();
                }
            }
            _loc_3.x = 181;
            _loc_3.y = 38;
            this.addChild(_loc_3);
            this.curPanel = _loc_3;
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.x = (Global.stage.stageWidth - this.width) / 2;
            this.y = (Global.stage.stageHeight - this.height) / 2;
            return;
        }// end function

    }
}
